#coding = utf-8
from selenium import webdriver
import time
import re
driver = webdriver.Chrome('C:/Program Files (x86)/Google/Chrome/Application/chromedriver')
driver.get("http://weixin.sogou.com/")
time.sleep(0.3)
driver.find_element_by_id("upquery").send_keys("小西的笔记")
driver.find_element_by_class_name("swz2").click()
print(driver.title)
now_handle = driver.current_window_handle
driver.find_element_by_xpath('//*[@id="sogou_vr_11002301_box_2"]').click()
time.sleep(10)
all_handle=driver.window_handles
for handle in all_handle:
    print(handle)
    if(handle!=now_handle):
        driver.switch_to_window(handle)
        if(driver.title=="请输入验证码"):
            driver.switch_to_window(handle)
        else:
            print(u"当前网页title" + driver.title)
            time.sleep(10)
            mnow_handle = driver.current_window_handle
            driver.find_element_by_xpath('//*[@id="WXAPPMSG1000000009"]/div/h4').click()
            time.sleep(3)
            mall_handle = driver.window_handles
            for mhandle in mall_handle:
                print(mhandle)
                if(mhandle!=mnow_handle):
                    driver.switch_to_window(handle)
                    print(u"当前网页title  " + driver.title)
                    msour=driver.page_source
                    print(msour)
                    #print(driver.current_url)
                    #print(driver.find_element_by_xpath('//*[@id="js_content"]/blockquote[2]/section/p[1]'))

driver.quit()

